function ccR_Rogue_Evasion()
	local UseAbility = ccRS.Rogue_UseEvasion
	local HealthToUseAbility = ccRS.Rogue_EvasionHP
	local Ability = EVASION
	if UseAbility
	and ccrPlayerHealth() <= HealthToUseAbility
	and ccrPlayerHasSpell(Ability)
	and SpellIsReady(Ability)
	then
		ccrCast(Ability)
	end
	return
end

function ccR_Rogue_Build_Combo_Point()
	-- Combat
	if ccrPlayerSpec() == 2 then
		local vCount = ccrPlayerCount(10)
		if ccrPlayerHasSpell(FAN_OF_KNIVES) then
			-- Sinister Strike
			if vCount == 1
			and SpellCanAttack(SINISTER_STRIKE)
			then
				ccrCastAttack(SINISTER_STRIKE)
				return
			end
			-- Fan of Knives
			if vCount > 1
			and SpellIsReady(FAN_OF_KNIVES)
			then
				ccrCast(FAN_OF_KNIVES)
				return
			end
		else
			if SpellCanAttack(SINISTER_STRIKE) then
				ccrCastAttack(SINISTER_STRIKE)
				return
			end
		end
	end
	return
end

function ccR_Rogue_Slice_And_Dice()
	if ccrPlayerComboPoints() == 0 then
		ccR_Rogue_Build_Combo_Point()
	else
		if SpellIsReady(SLICE_AND_DICE) then
			ccrCast(SLICE_AND_DICE)
			return
		end
	end
	return
end

function ccR_Rogue_Rupture()
	local vComboPoints
	-- Use less CP on faster to kill content
	if ccrPlayerLevel() >= 10 and ccrPlayerLevel() <= 84 then
		vComboPoints = 3
	end
	if ccrPlayerLevel() >= 85 then
		vComboPoints = 4
	end

	if ccrPlayerComboPoints() < vComboPoints then
		ccR_Rogue_Build_Combo_Point()
	else
		if SpellCanAttack(RUPTURE) then
			ccrCastAttack(RUPTURE)
			return
		end
	end
	return
end

function ccR_Rogue_Eviscerate()
	local vComboPoints
	-- Use less CP on faster to kill content
	if ccrPlayerLevel() >= 10 and ccrPlayerLevel() <= 84 then
		vComboPoints = 3
	end
	if ccrPlayerLevel() >= 85 then
		if (ccrTargetIsElite()
		or ccrTargetIsBoss())
		then
			vComboPoints = 4
		else
			vComboPoints = 3
		end

	end

	if ccrPlayerComboPoints() < vComboPoints then
		ccR_Rogue_Build_Combo_Point()
	else
		if SpellCanAttack(EVISCERATE) then
			ccrCastAttack(EVISCERATE)
			return
		end
	end
	return
end

function ccR_Rogue_Blade_Flurry()
	local UseAbility = ccRS.Rogue_2_UseBladeFlurry
	local EnemiesToUseAbility = ccRS.Rogue_2_BladeFlurryCount
	local Ability = BLADE_FLURRY
	if UseAbility then
		if #tblPGetMeleeEnemies >= EnemiesToUseAbility
		and ccrPlayerHasSpell(Ability)
		and SpellIsReady(Ability)
		and not ccrPlayerHasBuff(BLADE_FLURRY)
		then
			ccrCast(Ability)
			return
		end

		if ccrPlayerHasBuff(BLADE_FLURRY)
		and #tblPGetMeleeEnemies < EnemiesToUseAbility
		then
			CancelUnitBuff("player", GetSpellInfo(BLADE_FLURRY))
			return
		end
	end
	return
end

function ccR_Rogue_Kick()
	local UseAbility = ccRS.Rogue_UseKick
	if UseAbility
	and ccrPlayerHasSpell(KICK)
	and SpellIsReady(KICK)
	and ccrTargetIsCastingOrChanneling()
	and ccrTargetIsInteruptable()
	then
		if ccrTargetIsChanneling() then
			ccrCastAttack(KICK)
			return
		end
		if ccrTargetIsCasting()
		and ccrTargetHasLeftOnCast(1)
		then
			ccrCastAttack(KICK)
			return
		end
	end
end

function ccR_Rogue_Gouge()
	local UseAbility = ccRS.Rogue_UseGouge
	if UseAbility
	and ccrPlayerHasSpell(GOUGE)
	and SpellIsReady(GOUGE)
	and ccrTargetIsCastingOrChanneling()
	and (
		not SpellIsReady(KICK)
		or
		not ccrTargetIsInteruptable()
		)
	and SpellCanAttack(GOUGE)
	and ccrTargetIsFacingMe()
	and not ccrTargetIsBoss()
	then
		ccrCastAttack(GOUGE)
		return
	end
end

function ccR_Rogue_Distract()
	if ccRS.Rogue_UseDistract 
	and ccrPlayerHasSpell(DISTRACT)
	and SpellIsReady(DISTRACT)
	and not ccrPlayerHasTalent(CLOAK_AND_DAGGER)	-- Pointless to use distract if we have this talent
	and not ccrTargetIsInCombat()
	then
		if ccrValidTarget()
		and Target:GetDistance() <= 32
		and Target:IsFacing(Player) then
			ccrCast(DISTRACT);
			CastAtLocation(GetPointBetweenObjects(Target, Player, -1));
			return
		end
	end
	return
end

function ccR_Rogue_Adrenaline_Rush()
	if ccRS.Rogue_2_UseAdrenalineRush
	and ccrPlayerHasSpell(ADRENALINE_RUSH)
	and SpellIsReady(ADRENALINE_RUSH)
	and ccrPlayerEnergy() <= 15
	then
		ccrCast(ADRENALINE_RUSH)
		return
	end
end

function ccR_Rogue_Dismantle()
	if ccRS.Rogue_UseDismantle
	and SpellCanAttack(DISMANTLE)
	and (vLastDismantleAttempt == nil or (GetTime()-vLastDismantleAttempt > 3))
	then
		ccrCastAttack(DISMANTLE)
		vLastDismantleAttempt = GetTime()
		return
	end
end

function ccR_Rogue_Cloak_of_Shadows()
	if ccRS.Rogue_UseCloakOfShadows
	and SpellIsReady(CLOAK_OF_SHADOWS) 
	then
		for i = 1, 40 do
			local vDebuff={UnitDebuff("Player", i)}
			if vDebuff[i] == nil then
				break
			else
				if vDebuff[5] == "Poison"
				or vDebuff[5] == "Disease"
				then
					ccrCast(CLOAK_OF_SHADOWS)
				end
			end
		end
	end
end

function ccR_Rogue_Killing_Spree()
	local vMobCount = ccRS.Rogue_2_KillingSpreeCount
	if ccRS.Rogue_2_UseKillingSpree
	and ccrPlayerHasSpell(KILLING_SPREE)
	and SpellIsReady(KILLING_SPREE)
	and not ccrPlayerHasBuff(ADRENALINE_RUSH)
	and ccrPlayerEnergy() <= 25
	then
		local vCount = ccrPlayerCount(10)
		if (vCount >= vMobCount)
		or ccrTargetIsBoss()
		or ccrTargetIsEnemyPlayer()
		then
			ccrCast(KILLING_SPREE)
			return
		end
	end
end

function ccR_Rogue_Shadow_Blades()
	-- Combat
	if ccrPlayerSpec() == 2 then
		if ccrPlayerHasBuff(ADRENALINE_RUSH)
		and SpellIsReady(SHADOW_BLADES)
		then
			ccrCast(SHADOW_BLADES)
			return
		end
	end
end